package com.liveinstars.activity.application.endpoint;

import com.liveinstars.activity.application.service.ClockInApplicationService;
import com.liveinstars.api.dto.ClockinDto;
import com.liveinstars.api.facade.IClockInApi;
import com.onepiece.shipelves.common.Result;
import com.onepiece.shipelves.common.enums.SystemExceptionEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClockInEndpoint implements IClockInApi {


    @Autowired
    ClockInApplicationService clockInApplicationService;



    @Override
    public Result<ClockinDto> getDetailById(Integer id) {
        Result<ClockinDto> result = new Result<>();
        try {
            ClockinDto detail = clockInApplicationService.getDetailById(id);
            result.setData(detail);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }

    @Override
    public Result<ClockinDto> getMyClockIn(Integer userId, Integer activityId) {

        Result<ClockinDto> result = new Result<>();
        try {
            ClockinDto detail = clockInApplicationService.getMyClockIn(userId, activityId);
            result.setData(detail);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }

    @Override
    public Result<ClockinDto> create(ClockinDto dto) {
        Result<ClockinDto> result = new Result<>();
        try {
            ClockinDto detail = clockInApplicationService.createClockIn(dto);
            if(detail == null){
                result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
            }else {
                result.setData(detail);
            }
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }


}
